<?php
namespace app\common\tools;
/**
 * Bin 工具类
 */
class BinTools
{
	static public function judgeType($account)
	{
		/**
		 * 根据账户名称,判断分辨是什么形式
		 */
		if(strpos($account,'@'))
		{
			return 'email';
		}else{
			return 'telphone';
		}
	}

	/**
	 * [tree 分类]
	 * http://www.thinkphp.cn/code/170.html
	 * @param  [type]  &$data [description]
	 * @param  integer $pid   [description]
	 * @param  integer $count [description]
	 * @return [type]         [description]
	 */
    static public function tree(&$data,$pid = 0,$count = 1) {
        foreach ($data as $key => $value){
            if($value['pid']==$pid){
                $value['count'] = $count;
                self::$treeList []=$value;
                unset($data[$key]);
                self::tree($data,$value['id'],$count+1);
            } 
        }
        return self::$treeList ;
    }

    static public function tree2($items)
    {
		foreach ($items as $item) 
			$items[$item['pid']]['son'][$item['id']] = &$items[$item['id']]; 
		return isset($items[0]['son']) ? $items[0]['son'] : array(); 
    }

    static public function collectToTree($item)
    {
    	//由数据库的数组集直接返回SON型
    	$items = [];
    	foreach ($item as $v) {
    		$items[$v['id']] = $v;
    	}

    	return self::tree2($items);
    }

}